package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PspSpecCheckContDao;
import com.fdb.efp.nls.service.domain.PspSpecCheckCont;
import com.fdb.efp.nls.service.facade.PspSpecCheckContService;
import com.fdb.efp.nls.service.vo.PspSpecCheckContVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 专项检查合同表				<p>
 * @author chenqm1
 * @date 2018-05-04
 */
@Service("pspSpecCheckContService")
public class PspSpecCheckContServiceImpl implements PspSpecCheckContService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspSpecCheckContServiceImpl.class);

	@Autowired
	private PspSpecCheckContDao pspSpecCheckContDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspSpecCheckCont(List<PspSpecCheckContVO> inPspSpecCheckContVo) {
		logger.debug("当前新增数据为:"+ inPspSpecCheckContVo.toString());
		int num = 0;
		try {
//			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
//			beanCopy(inPspSpecCheckContVo, pspSpecCheckCont);
			num = pspSpecCheckContDao.insertPspSpecCheckCont(inPspSpecCheckContVo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspSpecCheckContVO inPspSpecCheckContVo) {
		logger.debug("当前删除数据条件为:"+ inPspSpecCheckContVo);
		int num = 0;
		try {
			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(inPspSpecCheckContVo, pspSpecCheckCont);
			num = pspSpecCheckContDao.deleteByPk(pspSpecCheckCont);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckContVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PspSpecCheckContVO inPspSpecCheckContVo) {
		logger.debug("当前修改数据为:"+ inPspSpecCheckContVo.toString());
		int num = 0;
		try {
			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(inPspSpecCheckContVo, pspSpecCheckCont);
			num = pspSpecCheckContDao.updateByPk(pspSpecCheckCont);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspSpecCheckContVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PspSpecCheckContVO queryByPk(PspSpecCheckContVO inPspSpecCheckContVo) {
		
		logger.debug("当前查询参数信息为:"+ inPspSpecCheckContVo);
		try {
			PspSpecCheckCont queryPspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(inPspSpecCheckContVo, queryPspSpecCheckCont);
			PspSpecCheckCont queryRslPspSpecCheckCont = pspSpecCheckContDao.queryByPk(queryPspSpecCheckCont);
			if (Objects.nonNull(queryRslPspSpecCheckCont)) {
				PspSpecCheckContVO outPspSpecCheckContVo = beanCopy(queryRslPspSpecCheckCont, new PspSpecCheckContVO());
				logger.debug("当前查询结果为:"+ outPspSpecCheckContVo.toString());
				return outPspSpecCheckContVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckContVO> queryAllOwner(PspSpecCheckContVO pspSpecCheckContVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		PspSpecCheckCont pspSpecCheckCont = beanCopy(pspSpecCheckContVo, new PspSpecCheckCont());
		List<PspSpecCheckContVO> list = null;
		try {
			List<PspSpecCheckCont> pspSpecCheckConts = pspSpecCheckContDao.queryAllOwnerByPage(pspSpecCheckCont);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspSpecCheckConts.size());
			pageSet(pspSpecCheckConts, pspSpecCheckCont);
			list = (List<PspSpecCheckContVO>) beansCopy(pspSpecCheckConts, PspSpecCheckContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckContVO> queryAllCurrOrg(PspSpecCheckContVO pspSpecCheckContVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		PspSpecCheckCont pspSpecCheckCont = beanCopy(pspSpecCheckContVo, new PspSpecCheckCont());
		List<PspSpecCheckCont> pspSpecCheckConts = pspSpecCheckContDao.queryAllCurrOrgByPage(pspSpecCheckCont);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspSpecCheckConts.size());
		List<PspSpecCheckContVO> list = null;
		try {
			pageSet(pspSpecCheckConts, pspSpecCheckCont);
			list = (List<PspSpecCheckContVO>) beansCopy(pspSpecCheckConts, PspSpecCheckContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckContVO> queryAllCurrDownOrg(PspSpecCheckContVO pspSpecCheckContVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		PspSpecCheckCont pspSpecCheckCont = beanCopy(pspSpecCheckContVo, new PspSpecCheckCont());
		List<PspSpecCheckCont> pspSpecCheckConts = pspSpecCheckContDao.queryAllCurrDownOrgByPage(pspSpecCheckCont);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspSpecCheckConts.size());
		List<PspSpecCheckContVO> list = null;
		try {
			pageSet(pspSpecCheckConts, pspSpecCheckCont);
			list = (List<PspSpecCheckContVO>) beansCopy(pspSpecCheckConts, PspSpecCheckContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
	/**
	 * 根据bizSerno删除数据
	 */
	public int deleteBybiz(String bizSerno) {
		logger.debug("当前删除数据条件为:"+ bizSerno);
		int num = 0;
		try {
			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(bizSerno, pspSpecCheckCont);
			num = pspSpecCheckContDao.deleteBybiz(bizSerno);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ bizSerno +"删除的数据条数为"+ num);
		return num;
	}

	/**
	 * 根据bizSerno查询
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<PspSpecCheckContVO> querySerno(String bizSerno) {
		// TODO Auto-generated method stub
		logger.debug("当前查询数据条件为:"+ bizSerno);
		List<PspSpecCheckContVO> lists = null;
		try {
			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(bizSerno, pspSpecCheckCont);
			List<PspSpecCheckCont> pspSpecCheckConts = pspSpecCheckContDao.querySerno(bizSerno);
			lists = (List<PspSpecCheckContVO>) beansCopy(pspSpecCheckConts, PspSpecCheckContVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return lists;
	}

	@Override
	public List<PspSpecCheckContVO> queryCtr(PspSpecCheckContVO pspSpecCheckContVo) {
		logger.debug("当前查询数据条件为:"+ pspSpecCheckContVo);
		List<PspSpecCheckContVO> lists = null;
		try {
			PspSpecCheckCont pspSpecCheckCont = new PspSpecCheckCont();
			beanCopy(pspSpecCheckContVo, pspSpecCheckCont);
			List<PspSpecCheckCont> pspSpecCheckConts = pspSpecCheckContDao.queryCtr(pspSpecCheckCont);
			lists = (List<PspSpecCheckContVO>) beansCopy(pspSpecCheckConts, PspSpecCheckContVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return lists;
	}

	//查询存在待提交的合同号
	@Override
	public List<String> querySpecCheckStatus() {
		List<String> queryContNo= pspSpecCheckContDao.querySpecCheckStatus();
		return queryContNo;
	}
	
}
